# -*- coding: utf-8 -*-
import urllib
import sys
import re


unicode_std = '6.0.0'
url = 'http://www.unicode.org/Public/' + unicode_std + '/ucd/Blocks.txt'

page = urllib.urlopen(url).read()
if ( page.find('Unicode Character Database') == -1 ):
        print 'Seems we\'ve downloaded wrong page'
        sys.exit(-1)
if ( page.find('Start Code..End Code; Block Name') == -1 ):
        print 'Seems unicode consorcium has changed blocks.txt format'
        sys.exit(-1)

format = re.compile("^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\\s*;\\s*(.+)$", re.MULTILINE)


for i in re.finditer(format, page):
        print 'addBlock(\"' + i.group(3) + '\", ' + \
                'Arrays.asList(new IntInterval(0x' + i.group(1) + ', 0x' + i.group(2) + ')));'
